--
-- Author: shunguo.chen
-- Date: 2016-10-19 18:35:59
--

local GameDB = import(".GameDB")

local function orderFunc( a, b )
    if a.sort and b.sort then
	   return tonumber( a.sort ) < tonumber( b.sort )
    else
        return tonumber( a.ID ) < tonumber( b.ID )
    end
end

function GameDB:queryTeamTargetSurfacesByType(tp)
    return self:getCachedValues("teamTarget_surface",
        function(v) 
            return tonumber(v.type) == tonumber( tp )
        end,
        orderFunc)
end

function GameDB:queryTeamTargetSurfaceById(id)
    return self:getCachedValue("teamTarget_surface", id)
end

function GameDB:queryTeamTargetTypes()
    return self:getCachedTable("teamTarget_type")
end

function GameDB:queryTeamTargets()
    return self:getCachedTable("teamTarget")
end

function GameDB:queryTeamTargetById(id)
    return self:getCachedValue("teamTarget", id)
end

function GameDB:queryTeamRobotById(id)
    return self:getCachedValue("teamTarget_robot", id)
end

function GameDB:getTeamThirdTargetMapId(id)
    local mapId
    local conf = self:queryTeamTargetById(id)
    if conf then
        mapId = tonumber(conf.battleMapId)
    end
    return mapId
end


function GameDB:queryDungeonPVEInfoById(id)
    local conf = self:getCachedValue("dungeon_pve", id )
    return conf
end

function GameDB:queryPvpSeasonConf(lv)
    return self:getCachedValue("season_expReward", lv)
end

function GameDB:queryChampionshipsConf(id)
    return self:getCachedValue("championships", id)
end

function GameDB:queryCosplayTargetConf(id)
    return self:getCachedValue("rolePlayConfig", id)
end

function GameDB:queryCosplayConf(id)
    return self:getCachedValue("rolePlayPool", id)
end

function GameDB:queryCosplayConfs()
    return self:getCachedValues("rolePlayPool")
end

function GameDB:queryCosplayPropConf(id)
	return self:getCachedValue("roleProp", id)
end

function GameDB:queryChessActionConf(id)
    return self:getCachedValue("chess_action", id)
end

function GameDB:queryChessBuffConf(id)
    return self:getCachedValue("buff_ingame", id)
end

function GameDB:queryTheatreTargetConf(id)
    return self:getCachedValue("theatrePool", id)
end

function GameDB:getTheatrePar(key, isInt)
    local conf = self:getCachedValue("theatreConfig", function(v)
       return v.theatrePar == key
    end)

    if isInt then
        ret = tonumber(conf.par)
    else
        ret = conf.strPar
    end
    -- print("GameDB:getTheatrePar", key, isInt, ret)
    return ret
end

return GameDB
